package gcj2012.round1a;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.korifey.ffalg.NumberTheory;
import org.korifey.ffalg.Probabilities;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class B extends AbstractRunner {
	
	
	@Override
	public void handleCase(int caseNumber) throws Exception {
		int n = scanner.nextInt();
		int [] a = new int[n];
		int [] b = new int[n];
		for (int i=0; i<n; i++) {
			a[i] = scanner.nextInt();
			b[i] = scanner.nextInt();
		}
		
		int res = 0;
		int money = 0;
		int handled = 0;
		while (handled < n) {
			int star1 = -1;
			int star2 = -1;
			for (int i=0; i<n; i++) {
				if (a[i] >= 0 && a[i] <= money) {
					if (star1 < 0 || (star1 >= 0 && b[i] > b[star1]))
					star1 = i;
				}
				if (b[i] >= 0 && b[i] <= money) {
					star2 = i;
				}
			}
			
			res ++;
			if (star2 >= 0) {
				if (a[star2] >= 0) money += 2;
				else money += 1;		
				
				a[star2] = -1;
				b[star2] = -1;
				handled ++;
			} else if (star1 >= 0) {
				a[star1] = -1;
				money += 1;
			} else {
				out.write("Too Bad\n");
				return;
			}
		}
		
		out.write(res+"\n");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new B().init(SIZE.large).execute();
	}

}
